import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'
const store = createStore({
  plugins: [createPersistedState({
    // key: 'vuex',
    storage: sessionStorage,
    paths: ['token', 'name']
  })],
  state: {
    name: 'test',
    age: 18,
    sex: '男',
    token: ''
  },
  mutations: {
    SET_NAME (state: any, payload: string) {
       state.name = payload
    },
    SET_TOKEN (state: any, payload: string) {
        state.token = payload
     }
  },
  actions: {
    Login({commit}, payload) {
       console.log(payload)
       // 1. 发送http请求 res = Http.login(payload)
       setTimeout(() => {
        // 2. 拿到token之后更新state.token // res.data.token
        commit('SET_TOKEN', '122222xxxf')
       }, 2000)
    }
  
  }
})


export default store

// export default createStore({

   
// })